<template>
  <div class="app-container">
    <el-form :inline="true" :model="listQuery" class="demo-form-inline" @submit.native.prevent>
      <el-form-item label="用户名">
        <el-input v-model="listQuery.q_memberName" style="width: 200px;" size="small" class="filter-item" />
      </el-form-item>
      <el-form-item label="提现编号">
        <el-input v-model="listQuery.q_code" style="width: 200px;" size="small" class="filter-item" />
      </el-form-item>
      <el-form-item label="申请状态">
        <el-select v-model="listQuery.q_state" size="small" placeholder="请选择">
          <el-option
            v-for="item in drawingState"
            :label="item.name"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button class="filter-item" size="small" type="primary" @click="check">查询</el-button>
        <el-button class="filter-item" size="small" type="primary" @click="rest">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="button-table-margin">
      <el-button size="small" type="primary" @click="auditing" v-permission="['admin/member/drawmoney/auditing']">通过</el-button>
      <el-button size="small" type="primary" @click="reject" v-permission="['admin/member/drawmoney/reject']">拒绝</el-button>
      <el-button size="small" type="primary" @click="paid" v-permission="['admin/member/drawmoney/paid']">已打款</el-button>
    </div>
    <el-table
      ref="singleTable"
      :data="dataList"
      v-loading="listLoading"
      border
      fit
      highlight-current-row
      @current-change="handleCurrentChange"
      style="width: 100%">
      <el-table-column
        type="index"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        property="memberName"
        label="用户名"
        width="150">
      </el-table-column>
      <el-table-column
        property="code"
        width="200"
        label="提现编号">
      </el-table-column>
      <el-table-column
        property="money"
        width="150"
        label="提现金额">
      </el-table-column>
      <el-table-column
        property="createTime"
        width="200"
        label="申请时间">
      </el-table-column>
      <el-table-column
        property="auditingTime"
        width="200"
        label="审核时间">
      </el-table-column>
      <el-table-column
        property="handleTime"
        width="200"
        label="打款时间">
      </el-table-column>
      <el-table-column
        property="bank"
        width="200"
        label="收款银行">
      </el-table-column>
      <el-table-column
        property="bankCode"
        width="200"
        label="收款账号">
      </el-table-column>
      <el-table-column
        property="state"
        width="100"
        label="处理状态">
        <template slot-scope="scope">
          {{ codeBox.MEMBER_DRAWING_STATE[scope.row.state] }}
        </template>
      </el-table-column>
      <el-table-column
        property="optName"
        width="150"
        label="处理人">
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import { memberApplyDrawingList, memberApplyDrawingAuditing, memberApplyDrawingReject, memberApplyDrawingPaid} from '@/api/member'
import Pagination from '@/components/Pagination'
import { Message } from 'element-ui'
import { getCodeManager,codeToArray } from '@/api/all'
export default {
  name: 'memberdrawinglist',
  components: { Pagination },
  data() {
    return {
      dataList: [],
      drawingState: [],
      total: 0,
      listLoading: false,
      listQuery: {
        page: 1,
        limit: 20,
        q_memberName: '',
        q_code: '',
        q_state: ''
      }
    }
  },
  created() {
    getCodeManager('MEMBER_DRAWING_STATE', () => {
      this.drawingState = codeToArray('MEMBER_DRAWING_STATE');
    })
    this.getList()
  },
  methods:{
    handleCurrentChange(val) {
      // 选中当前行数据
      this.currentRow = val
    },
    // 获取列表数据
    getList() {
      this.listLoading = true
      memberApplyDrawingList(this.listQuery).then(response => {
        this.dataList = response.data.rows
        this.total = response.data.total
        this.listLoading = false
      })
    },
    check() {
      this.getList()
    },
    rest() {
      this.listQuery = {
        page: 1,
        limit: 20,
        q_memberName: '',
        q_code: '',
        q_state: ''
      }
      this.getList()
    },
    auditing() {
      if(this.currentRow == null) {
        Message.error('请选择一条记录')
        return
      }
      if(this.currentRow.state != 1) {
        Message.error('只有状态为待审核的申请才能审核')
        return
      }
      this.$confirm('确定审核通过吗？', '提示', {
        onfirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        memberApplyDrawingAuditing({id: this.currentRow.id}).then(res => {
          if(res.data.success) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            });
            this.getList()
          } else {
            this.$message({
              type: 'error',
              message: res.data.message
            });
          }
        })
      })
    },
    reject() {
      if(this.currentRow == null) {
        Message.error('请选择一条记录')
        return
      }
      if(this.currentRow.state != 1) {
        Message.error('只有状态为待审核的申请才能驳回操作')
        return
      }
      this.$confirm('确定驳回申请吗？', '提示', {
        onfirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        memberApplyDrawingReject({id: this.currentRow.id}).then(res => {
          if(res.data.success) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            });
            this.getList()
          } else {
            this.$message({
              type: 'error',
              message: res.data.message
            });
          }
        })
      })
    },
    paid() {
      if(this.currentRow == null) {
        Message.error('请选择一条记录')
        return
      }
      if(this.currentRow.state != 2) {
        Message.error('只有审核通过的提款申请才能操作')
        return
      }
      this.$confirm('确定已经向用户支付了提现金额了吗？', '提示', {
        onfirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        memberApplyDrawingPaid({id: this.currentRow.id}).then(res => {
          if(res.data.success) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            });
            this.getList()
          } else {
            this.$message({
              type: 'error',
              message: res.data.message
            });
          }
        })
      })
    }
  }
}
</script>

<style>
  .filter-container .el-col-6 {
    margin-bottom: 15px;
  }
  .filter-item {
    margin-bottom: 0
  }
  /deep/ .filter-container label {
    font-size: 14px;
    font-weight: 500;
    margin-right: 10px;
  }
</style>
